package IOC.C2_resources.C2_3_resourcesImplementations.C2_3_1_resourcesImplementationsUrlresource;

import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
import org.junit.Test;
import org.springframework.core.io.UrlResource;

import java.util.List;

/**
 * @author xufy
 * @version 1.0
 **/
public class UrlResourceTest {

    //accessible with a URL, such as files, an HTTPS target, an FTP target, and others

    @Test
    public  void loadAndReadUrlResource() throws Exception {

        String path = "file://D:\\StudyProject\\spring-5.3.9-learning\\spring-core\\src\\main\\java\\IOC\\C2_resources\\C2_3_resourcesImplementations\\C2_3_1_resourcesImplementationsUrlresource\\books.xml";
        UrlResource resource = new UrlResource(path);
        // 获取文件名
        System.out.println("================ resource.getFileName = " + resource.getFilename());


        String path1 = "https://www.baidu.com";
        UrlResource resource1 = new UrlResource(path1);
        // 获取文件名
        System.out.println("========:" + resource1.getFilename()
          +"     ##########:   "+ resource1.getURL()
                +"     @@@@@@@@:   "+ resource1.getURL().getProtocol()
                +"     &&&&&&&&&:   "+ resource1.getURL().getHost()
        );


        String path2 = "www.baidu.com";
        UrlResource resource2 = new UrlResource(path2);
        System.out.println(" ************  "+resource2.getFilename());
    }
}
